package com.spzx.auth.controller;

import com.spzx.auth.form.H5RegisterBody;
import com.spzx.auth.form.LoginBody;
import com.spzx.auth.service.H5UserInfoService;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.security.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("h5")
@Tag(name = "移动端个人信息模块")
public class H5TokenController extends BaseController {
    @Resource
    H5UserInfoService h5UserInfoService;
    ///h5/register

    @Operation(summary = "会员注册接口")
    @PostMapping("register")
    public AjaxResult register(@RequestBody H5RegisterBody h5RegisterBody) {
        return toAjax(h5UserInfoService.register(h5RegisterBody));
    }

    @Operation(summary = "会员登录接口")
    @PostMapping("login")
    public R<Map<String,Object>> login(@RequestBody LoginBody loginBody) {
        return R.ok(h5UserInfoService.login(loginBody));
    }

    @Operation(summary = "会员注销接口")
    @DeleteMapping("logout")
    public AjaxResult logout(){
        Long userId = SecurityUtils.getUserId();
      return toAjax( h5UserInfoService.logout(userId));

    }


}
